package common

import (
	"encoding/json"
	"sixiao.lcol.top/admin/tools"
	"io/ioutil"
	"log"
)

type DatabaseConfig struct {
	Server   string
	Port     int
	Database string
	Username string
	Password string
}

func GetDbConf() *DatabaseConfig {
	var config = &DatabaseConfig{}
	isExist, _ := tools.IsFileExist(DbConfigFilename)
	if !isExist {
		return config
	}
	info, err := ioutil.ReadFile(DbConfigFilename)
	if err != nil {
		return config
	}
	err = json.Unmarshal(info, config)
	if err != nil {
		log.Println(err)
		return nil
	}
	return config

}
